package com.wteam.controller;


import com.wteam.PoJo.DTO.CommentDTO;
import com.wteam.PoJo.DTO.PageQuery;
import com.wteam.PoJo.DTO.ReplyCommentDTO;
import com.wteam.PoJo.VO.ReplyCommentVO;
import com.wteam.Service.IPostworkService;
import com.wteam.until.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-16
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论模块")
public class CommentController {
    @Autowired
    private IPostworkService iPostworkService;
    @PostMapping("/postwork")
    @ApiOperation("评论帖子(帖子)")
    @Transactional(rollbackFor = Exception.class)
    public Result compostwork(@RequestBody CommentDTO commentDTO) {
        return iPostworkService.compostwork(commentDTO);
    }



    @DeleteMapping("/postwork/{id}")
    @ApiOperation("根据评论表id删除评论(帖子)")
    @Transactional(rollbackFor = Exception.class)
    public Result deletepostwork(@ApiParam("评论表主键id")@PathVariable Long id) {
        return iPostworkService.deletecompostwork(id);
    }


    @PutMapping("/replycom/{commentid}")
    @ApiOperation("根据评论表id查看回复(帖子)")
    public Result<ReplyCommentVO> viewreplycomment(@PathVariable @ApiParam("评论表的主键id") Long commentid
            , @RequestBody PageQuery pageQuery) {
        return iPostworkService.viewreplycomment(commentid, pageQuery);
    }

    @PostMapping("/replycom")
    @ApiOperation("回复评论(帖子)")
    @Transactional(rollbackFor = Exception.class)
    public Result replycomment(@RequestBody ReplyCommentDTO replyCommentDTO) {
        return iPostworkService.replycomment(replyCommentDTO);
    }

    @DeleteMapping("/replycom/{id}")
    @ApiOperation("根据回复表id删除回复(帖子)")
    @Transactional(rollbackFor = Exception.class)
    public Result deletereply(@ApiParam("回复表id") @PathVariable Long id) {
        return iPostworkService.replydelete(id);
    }


}
